from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String, func, DECIMAL
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsOrderBill(Base):
    __tablename__ = 'cms_order_bill'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='主键id'),
        {'comment': '用车账单'}
    )
    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    state: Mapped[str] = mapped_column(String(16), comment='状态（未结算，已结算）')
    order_id: Mapped[Optional[str]] = mapped_column(String(32), comment='单号')
    car_id: Mapped[Optional[str]] = mapped_column(String(32), comment='车辆编码')
    driver_id: Mapped[Optional[str]] = mapped_column(String(32), comment='驾驶员编码')
    system_mileage: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='系统里程')
    sheet_mileage: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='仪表里程')
    expenses: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='系统里程费用')
    sheet_expenses: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='仪表里程费用')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, comment='创建时间', server_default=func.now())
    create_by: Mapped[Optional[str]] = mapped_column(String(32), comment='创建人')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='修改时间',
                                                                     server_default=func.now(), onupdate=func.now())
    update_by: Mapped[Optional[str]] = mapped_column(String(32), comment='修改人')
    bill_type: Mapped[Optional[str]] = mapped_column(String(32), comment='结算类型 北斗系统结算 表显里程结算')
    starting_expenses: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='起步价')
    day_expenses: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='固定费用')
    suspended_expenses: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='停延费用')
    sum_expenses: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment='总费用')


